// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import VueAxios from 'vue-axios'
import Vuex from 'vuex'

import App from './App'

import router from './router'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import axios from 'axios'

import store from './store'
import qs from 'qs'
import GoEasy from 'goeasy';
Vue.prototype.$goeasy=GoEasy
Vue.prototype.$qs=qs
Vue.use(store);
Vue.use(ElementUI)
Vue.use(Vuex);
Vue.use(VueAxios,axios)
Vue.config.productionTip = false



new Vue({
  el: '#app', store
})

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

// 在跳转前执行
router.beforeEach((to, form, next) => {
  // 获取用户登录状态
  let isLogin = sessionStorage.getItem('isLogin');




    // 注销
    if (to.path == '/logout') {
        // 清空
      sessionStorage.clear();
      // 跳转到登录
      next({path: '/login'});
    }



    // 如果请求的是登录页
    else if (to.path == '/login') {
        if (isLogin != null) {
        // 跳转到首页
        next({path: '/main'});
        }
    }




    // 如果为非登录状态
    else if (isLogin == null) {
    // 跳转到登录页
      next({
        path: '/login'
      });
    }
  // 下一个路由
   next();
});
